import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Register from '../components/login/Register.vue'
import Home from '../components/Home.vue'
import Forget from '../components/Forget.vue'
import HomePage from '../components/homevue/HomePage.vue'
import Employment from '../components/homevue/Employment.vue'
import Enterprise from '../components/homevue/StartBusiness.vue'
import Forum from '../components/homevue/Forum.vue'
import Policy from '../components/homevue/Policy.vue'
import Analysis from '../components/homevue/Analysis.vue'
import WriteArticle from '../components/Forum/WriteArticle.vue'
import ForumList from '../components/Forum/ForumList.vue'
import ForumDetails from '../components/Forum/ForumDetails.vue'
import WorkAnalyse from '../components/Analyse/WorkAnalyse.vue'
import Business from '../components/Analyse/Business.vue'
import PolicyAnalyse from '../components/Analyse/PoliycAnalyse.vue'
import Other from '../components//Analyse/Other.vue'
import ChangePwd from '../components/Management/ChangePwd.vue'
import CompleteInfo from '../components/Management/CompleteInfo.vue'
import PolicyDetail from '../components/Policy/policyDetail.vue'
import PublishInfo from '../components/Employment/PublishInfo.vue'
import NewsList from '../components/Employment/NewsList.vue'
import NewsDetail from '../components/Employment/NewsDetail.vue'
import OtherArtile from '../components/Employment/OtherArticle.vue'
import Recruit from '../components/Employment/Recruit.vue'
import SearchList from '../components/Search/SearchList.vue'
import SearchDetail from '../components/Search/SearchDetail.vue'
import ForumManagement from '../components/Management/ForumManagement.vue'
import InfoManagement from '../components/Management/InfoManagement.vue'
import UserInfo from '../components/Management/UserInfo.vue'
import ContentManagement from '../components/Management/ContentManage.vue'
import UpdateForum from '../components/Management/UpdateForum.vue'
import Work from '../components/Management/Work.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/Register',
    component: Register
  },
  {
    path: '/home',
    component: Home,
    redirect: '/homepage',
    children: [
      { path: '/homepage', component: HomePage },
      { path: '/employment', component: Employment },
      { path: '/enterprise', component: Enterprise },
      { path: '/forum', component: Forum },
      { path: '/policy', component: Policy },
      {
        path: '/analysis',
        component: Analysis,
        redirect: '/workanalyse',
        children: [
          { path: '/workanalyse', component: WorkAnalyse },
          { path: '/business', component: Business },
          { path: '/policyanalyse', component: PolicyAnalyse },
          { path: '/other', component: Other }
        ]
      },
      { path: '/forumdetails/:id', name: 'forumdetails', component: ForumDetails },
      { path: '/policyDetail/:id', name: 'policyDetail', component: PolicyDetail },
      { path: '/newsList/news_type/:news_type/sql/:sql/kind/:kind', name: 'newsList', component: NewsList },
      { path: '/newsdetail/id/:id/newsType/:newsType', name: 'newsdetail', component: NewsDetail },
      { path: '/otherArticle/id/:id/tableName/:tableName', name: 'otherArticle', component: OtherArtile },
      { path: '/recruit/:mytype', name: 'recruit', component: Recruit },
      { path: '/searchlist/type/:type/keyword/:keyword', name: 'searchlist', component: SearchList },
      { path: '/searchdetail/', name: 'searchdetail', component: SearchDetail },
      {
        path: '/contentManage',
        name: 'contentManage',
        component: ContentManagement,
        children: [
          { path: '/forumManagement', name: 'forumManagement', component: ForumManagement },
          { path: '/infoManagement', name: 'infoManagement', component: InfoManagement }
        ]
      }
    ]
  },
  {
    path: '/forget',
    component: Forget
  },
  {
    path: '/postarticle',
    component: WriteArticle
  },
  {
    path: '/forumlist',
    component: ForumList,
    children: []
  },
  { path: '/changePwd/:id', name: 'ChangePwd', component: ChangePwd },
  { path: '/completeInfo/:id', name: 'completeInfo', component: CompleteInfo },
  { path: '/publishInfo', component: PublishInfo },
  { path: '/userInfo', name: 'userInfo', component: UserInfo },
  { path: '/updateForum/:id', name: 'updateForum', component: UpdateForum },
  { path: '/work', name: 'work', component: Work }
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
// to将要访问的路径
// from 代表从哪个路径跳转而来
// next 是一个函数 表示放行
// next() 放行 next('/login') 强制跳转
// router.beforeEach((to, from, next) => {
// if (to.path === '/login') return next()
// 获取token
// const tokenStr = window.sessionStorage.getItem('token')
// if (!tokenStr) return next('/login')
// })

export default router
